<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="text" class="i1" placeholder="请输入数字1："><br>
<input type="text" class="i2"  placeholder="请输入数字2：">
<br><br>
<!--<button onclick="f()" id="jia">加</button>
<button onclick="f()" id = "jian">减</button>
<button onclick="f()" id = "cheng">乘</button>
<button onclick="f()" id = "chu">除</button>-->
<button onclick="f('+')" >加</button>
<button onclick="f('-')">减</button>
<button onclick="f('*')" >乘</button>
<button onclick="f('/')">除</button>

<h3>运算结果：<span id="result"></span></h3>
<script>
    function f(o) {
        let i1 = document.querySelector('.i1').value;
        let i2 = document.querySelector('.i2').value;
        let spanE = document.querySelector('#result');
        let n1 = parseFloat(i1);
        let n2 = parseFloat(i2);
        //let id = event.target.id;
       switch (o){
            case '+':
                spanE.innerHTML = n1 + n2;
                break;
            case '-':
                spanE.innerHTML = n1 - n2;
                break;
            case '*':
                spanE.innerHTML = n1 * n2;
                break;
            case '/':
                if(n2 != 0){
                    spanE.innerHTML = n1 / n2;
                }else{
                    alert('除数不能为0');
                }
                break;
        }
    }
</script>

</body>
</html>